# app/models/prediction_report.py
from app.db import db
import json

class PredictionReport(db.Model):
    __tablename__ = 'prediction_report'
    id = db.Column(db.Integer, primary_key=True)
    report_content = db.Column(db.Text)
    passed_percent = db.Column(db.Float)
    input_urls = db.Column(db.Text)  # 存储 input_urlList 的 JSON 字符串
    mask_urls = db.Column(db.Text)  # 存储 mask_urlList 的 JSON 字符串

    def get_report_dict(self):
        input_urls_list = json.loads(self.input_urls) if self.input_urls else []
        mask_urls_list = json.loads(self.mask_urls) if self.mask_urls else []
        return {
            '输入图片链接': input_urls_list,
            '掩码图片链接': mask_urls_list,
            '合格率': self.passed_percent
        }